package com.example.nsl;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class CustomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private List<String> itemBeens;

    private LayoutInflater layoutInflater;

    public CustomAdapter(Context context, List<String> itemBeens) {
        this.itemBeens = itemBeens;
        layoutInflater = LayoutInflater.from(context);
    }

    //创建ViewHolder
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item, parent, false);
        CustomViewHolder vh = new CustomViewHolder(itemView);
        return vh;
    }

    //绑定ViewHolder
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        String itemBean = itemBeens.get(position);
        final CustomViewHolder viewHolder = (CustomViewHolder) holder;
//        viewHolder.dataIv.setImageResource(itemBean.getResId());
//        viewHolder.dataTv.setText(itemBean.getTitle());
    }

    //返回数据源长度
    @Override
    public int getItemCount() {
        if (itemBeens == null) {
            return 0;
        }
        return itemBeens.size();
    }

    //自定义ViewHolder
    class CustomViewHolder extends RecyclerView.ViewHolder{


        public CustomViewHolder(View itemView) {
            super(itemView);

        }
    }

}